#include "CEC2017_F4.h"
#include "DumpLog.h"
namespace Solver
{

CEC2017_F4::CEC2017_F4(std::size_t dim):BaseTestFun(dim, FunType_E::CEC2017_F4_E, DifficultyLevel_E::Easy_E, "CEC2017_F4", "")
{
    passY_ = 1e-12;
    bestY_ = 0;
    std::fill(bestX_.begin(), bestX_.end(), 1);
}

CEC2017_F4::~CEC2017_F4()
{

}

value_t CEC2017_F4::calcMinFun(const VectorXd_t &x)
{
    //1.
    if (x.size() < 2)
    {
        LogError(name_ + " 函数维度不能小于2");
        return std::numeric_limits<value_t>::max();
    }

    //2.
    value_t sum1(0), sum2(0);
    const std::size_t num = x.size() - 1;
    for (std::size_t i = 0; i != num; ++i)
    {
        sum1 += std::pow(x[i] * x[i] - x[i+1], 2);
        sum2 += std::pow(x[i] - 1, 2);
    }

    return 100 * sum1 + sum2;
}

}